
package cz.cvut.fel.y36mm1.videostreaming.devicediscovery;

import cz.cvut.fel.y36mm1.videostreaming.Commander;
import cz.cvut.fel.y36mm1.videostreaming.screens.*;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.CommandListener;

/**
 * Visual component displaying all found devices
 * @author Jiri Chadima, chadij1
 */
public class DevicesScreen extends AbstractScreen /*implements CommandListener*/ {

	private ChoiceGroup choices;

	public DevicesScreen(String title, CommandListener cl) {
		super(null, title);
		setCommandListener(cl);
		initComponents();
	}

	public DevicesScreen(String title) {
		super(null, title);
		//discoverer = dd;
		initComponents();
	}

	/**
	 * Sets up all elements on screen, adds commands
	 */
	public void initComponents() {
		choices = new ChoiceGroup("Discovered devices", ChoiceGroup.EXCLUSIVE);
		append(choices);
		addCommand(Commander.RESTART_INQUIRY);
		addCommand(Commander.START_SERVER);
		addCommand(Commander.CONFIRM_DEVICE);
		//addCommand(Commander.TEST_START_CLIENT);
		addCommand(Commander.EXIT);
	}

	/**
	 * adds new device into choicegroup
	 * @param device
	 */
	public void newDeviceDiscovered(String device) {
		// prekreslovani funguje samos
		choices.append(device, null);
	}

	/**
	 * Adds "Search complete" note on screen
	 */
	public void addInquiryCompletedNote() {
		if(size() > 1) {
			delete(1);
		}
		append("Search complete.");
	}

	/**
	 * This doesn't work currently due to multithreading of device discovery
	 */
	public void noServerAvailable() {
		//append("No device able of receiving data found!");
	}

	public ChoiceGroup getChoices() {
		return choices;
	}

}
